package com.handpay.nocardpay.baselibrary.bill.presenter;

import android.content.Context;

import com.handpay.nocardpay.baselibrary.bill.model.IBillModel;
import com.handpay.nocardpay.baselibrary.bill.model.bean.BillBean;
import com.handpay.nocardpay.baselibrary.bill.model.impl.BillModelImpl;
import com.handpay.nocardpay.baselibrary.bill.view.IBillView;
import com.handpay.nocardpay.baselibrary.commbase.model.IBaseModel;
import com.handpay.nocardpay.baselibrary.commbase.model.bean.BaseErrorInfo;
import com.handpay.nocardpay.baselibrary.commbase.presenter.IBasePresenter;

import java.util.HashMap;

/**
 * Created by sxshi on 2017/8/16.
 */

public class BillPresenterImpl implements IBasePresenter {
    private Context mContext;
    private IBillView<BillBean> billView;
    private IBillModel<BillBean> billModel;

    public void setBillView(IBillView<BillBean> billView) {
        this.billView = billView;
    }

    public BillPresenterImpl(Context mContext) {
        this.mContext = mContext;
        billModel = new BillModelImpl(mContext);
    }

    public void queryBills(HashMap<String, Object> paramers, boolean isShowLoading) {
        if (billView != null) {
            if (isShowLoading) {
                billView.showProgress();
            }
        }

        billModel.queryBills(paramers, BillBean.class, new IBaseModel.OnRequestFinishedListener<BillBean>() {
            @Override
            public void onError(BaseErrorInfo baseErrorInfo) {
                if (billView != null) {
                    billView.hideProgress();
                    billView.showErrorAlert(baseErrorInfo);
                }
            }

            @Override
            public void onSuccess(BillBean response) {
                if (billView != null) {
                    billView.hideProgress();
                    billView.showBills(response);
                }
            }
        });
    }

    @Override
    public void onDestory() {
        if (billView != null)
            billView = null;
    }
}
